package cn.edu.ctbu.dp07.config;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        String uri = request.getRequestURI();
        if (uri.startsWith("/login") || uri.startsWith("/css/") || uri.startsWith("/js/") || uri.startsWith("/font/") || uri.startsWith("/images/")) {
            return true;
        }
        if (session.getAttribute("loginUser") != null) {
            return true;
        }
        response.sendRedirect("/login");
        return false;
    }
} 